home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 October
/
CHIP Turkiye Ekim 2000.iso
/
prog
/
naps
/
04
/
setup.exe
/
Gnucleus
/
PrefLanguage.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-07-15
|
7KB
|
235 lines
/********************************************************************************
Gnucleus - A node application for the Gnutella network
Copyright (C) 2000 John Marshall
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For support, questions, comments, etc...
E-Mail:
swabby@c0re.net
Address:
21 Cadogan Way
Nashua, NH, USA 03062
********************************************************************************/
// PrefLanguage.cpp : implementation file
//
#include "stdafx.h"
#include "Gnucleus.h"
#include "GnucleusDoc.h"
#include "PrefLanguage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrefLanguage property page
IMPLEMENT_DYNCREATE(CPrefLanguage, CPropertyPage)
CPrefLanguage::CPrefLanguage() : CPropertyPage(CPrefLanguage::IDD)
{
Doc = NULL;
//{{AFX_DATA_INIT(CPrefLanguage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CPrefLanguage::~CPrefLanguage()
{
}
void CPrefLanguage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPrefLanguage)
DDX_Control(pDX, IDC_BUTTON_ACTIVATE, m_btnActivate);
DDX_Control(pDX, IDC_BUTTON_UPDATE, m_btnUpdate);
DDX_Control(pDX, IDC_LIST_SELECT, m_lstSelect);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPrefLanguage, CPropertyPage)
//{{AFX_MSG_MAP(CPrefLanguage)
ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate)
ON_BN_CLICKED(IDC_BUTTON_ACTIVATE, OnButtonActivate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrefLanguage message handlers
BOOL CPrefLanguage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
Doc = (CGnucleusDoc *) ((CGnucleusApp *) AfxGetApp())->MasterDoc;
CRect rect;
// Setup shared list
m_lstSelect.GetWindowRect(&rect);
m_lstSelect.InsertColumn(0, "Module", LVCFMT_LEFT,
(rect.Width() - 30) * 2/3, 0);
m_lstSelect.InsertColumn(1, "Version", LVCFMT_LEFT,
(rect.Width() - 30) * 1/3, 1);
m_lstSelect.SetExtendedStyle(LVS_EX_FULLROWSELECT);
// Get language DLL's in current directory
OnButtonUpdate();
m_btnUpdate.EnableWindow(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
////////////////////////////////////////////////////////////
//! author="Nathan Brown"
//
//: Update the language list by looking in the current directory
//: for Language DLL's.
void CPrefLanguage::OnButtonUpdate()
{
// Get language DLL's in current directory
CFileFind finder;
FOUR64BIT version_num;
CString buffer;
version_num.dw64 = 0;
BOOL b_more_files = true;
bool b_found_lang_pack = false;
m_lstSelect.DeleteAllItems();
b_more_files = finder.FindFile("GNU_Lang_*.DLL");
while(b_more_files)
{
b_found_lang_pack = true;
b_more_files = finder.FindNextFile();
version_num.dw64 = util_GetVersionNumber((LPCTSTR)finder.GetFilePath());
buffer.Format("%u.%u.%u.%u", version_num.i1, version_num.i2, version_num.i3, version_num.i4);
m_lstSelect.InsertItem(0, (LPCTSTR)finder.GetFileName());
m_lstSelect.SetItem(0, 1, LVIF_TEXT, buffer, NULL, NULL, NULL, NULL);
}
// Now insert the default english selection
version_num.dw64 = util_GetVersionNumber("gnucleus.exe");
buffer.Format("%u.%u.%u.%u", version_num.i1, version_num.i2, version_num.i3, version_num.i4);
m_lstSelect.InsertItem(0, "Default (English)");
m_lstSelect.SetItem(0, 1, LVIF_TEXT, buffer, NULL, NULL, NULL, NULL);
if(b_found_lang_pack)
m_btnActivate.EnableWindow(TRUE);
else
m_btnActivate.EnableWindow(FALSE);
}
////////////////////////////////////////////////////////////
//! author="Nathan Brown"
//
//: Grabs the the selected language, and sets the program to those
//: setting, saves the INI, and then applys if possible
void CPrefLanguage::OnButtonActivate()
{
if(m_lstSelect.GetSelectedCount())
{
// Load new resource Dll as selected by user
CString str_lib_name = m_lstSelect.GetItemText( m_lstSelect.GetSelectionMark(), 0);
// handle default string
if(str_lib_name.Find("Default") != -1 || str_lib_name.Find("GNU_Lang") == -1)
Doc->m_strLangDLLex = "Default";
else
Doc->m_strLangDLLex = str_lib_name.Mid(str_lib_name.GetLength() - 7, 3);
// Don't apply midstream right now, because it doesn't work fully.
// Require the user to restart instead.
AfxMessageBox("Please restart program to apply changes.\n");
// CPrefLanguage::SwitchLanguge(Doc);
Doc->WriteINI();
}
}
BOOL CPrefLanguage::OnApply()
{
// TODO: Add your specialized code here and/or call the base class
return CPropertyPage::OnApply();
}
////////////////////////////////////////////////////////////
//! author="Nathan Brown"
//
//: Performs a program wide Language switch by loading and unloading
//: a language DLL.
void CPrefLanguage::StaticSwitchLanguge(CGnucleusDoc * Doc)
{
if(Doc->m_hLangDLL)
{
FreeLibrary(Doc->m_hLangDLL);
Doc->m_hLangDLL = NULL;
}
if(!Doc->m_strLangDLLex.IsEmpty() && Doc->m_strLangDLLex.Find("Default") == -1)
{
CString str_lib_name = "GNU_Lang_" + Doc->m_strLangDLLex + ".DLL";
Doc->m_hLangDLL = AfxLoadLibrary(str_lib_name);
ASSERT(Doc->m_hLangDLL);
AfxSetResourceHandle(Doc->m_hLangDLL);
/*
// now update main menu
HMENU hmen = ::LoadMenu( Doc->m_hLangDLL, MAKEINTRESOURCE(IDR_MAINFRAME));
HWND mainwnd = AfxGetMainWnd()->m_hWnd;
if (::IsWindow(mainwnd) && m_pParentWnd)
{
::SetMenu(mainwnd, hmen);
AfxGetMainWnd()->DrawMenuBar( );
}
*/
/*
else
// errorhandling
// Set idle message in statusbar
AfxGetMainWnd()->SendMessage(WM_SETMESSAGESTRING, (WPARAM)AFX_IDS_IDLEMESSAGE, 0L);
*/
}
}